<template>
    <div class="table">
        <el-breadcrumb separator="/" class="breadCrumb">
            <el-breadcrumb-item>{{$t('sidebar.hostMsg')}}</el-breadcrumb-item>
            <el-breadcrumb-item>{{$t('sidebar.taskHostStatus')}}</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="crumbs">
            <el-row :gutter="15">
                <el-col :span="2" style="min-width:100px;">
                    <el-input
                        :placeholder="$t('taskHostStatus.pleaseInput',{ name: 'ID' })"
                        v-model="searchForm.id">
                    </el-input>
                </el-col>
                <el-col :span="3" style="min-width:140px;">
                    <el-input
                        :placeholder="$t('taskHostStatus.pleaseInput',{ name: $t('taskHostStatus.hostUuid') })"
                        v-model="searchForm.hostId">
                    </el-input>
                </el-col>
                <el-col :span="3" style="min-width:150px;">
                    <el-input
                        :placeholder="$t('taskHostStatus.pleaseInput',{ name: $t('taskHostStatus.hostIp') })"
                        v-model="searchForm.hostIp">
                    </el-input>
                </el-col>
                <el-col :span="3" style="min-width:140px;">
                    <el-input
                        :placeholder="$t('taskHostStatus.pleaseInput',{ name: $t('taskHostStatus.taskProject') })"
                        v-model="searchForm.taskProject">
                    </el-input>
                </el-col>
                <el-col :span="2" style="min-width:135px;">
                    <el-select v-model="searchForm.status" clearable :placeholder="$t('taskHostStatus.pleaseInput',{ name: $t('taskHostStatus.status') })" style="width:100%;">
                        <el-option key="0" :label="$t('taskHostStatus.all')" value="0"></el-option>
                        <el-option key="1" :label="$t('taskHostStatus.online')" value="1"></el-option>
                    </el-select>
                </el-col>
                <el-col :span="4" style="line-height: 35px;">
                    <el-button size="small" type="primary" @click="searchData()">{{$t('taskHostStatus.search')}}</el-button>
                    <el-button size="small" type="primary" @click="refreshData()">{{$t('taskHostStatus.refresh')}}</el-button>
                </el-col>
            </el-row>
        </div>
        <el-table :data="tableData" border style="width: 100%" :max-height="$store.state.allTable.tableHeight" v-loading="tableDataLoading"
                  :element-loading-text="$t('allTable.dataLoading')">
            <el-table-column prop="id" label="ID" width="100">
            </el-table-column>
            <el-table-column prop="hostId" :label="$t('taskHostStatus.hostUuid')" min-width="400">
            </el-table-column>
            <el-table-column prop="hostIp" :label="$t('taskHostStatus.hostIp')" min-width="200">
            </el-table-column>
            <el-table-column prop="taskProject" :label="$t('taskHostStatus.taskProject')" min-width="300">
            </el-table-column>
            <el-table-column prop="createDate" :label="$t('taskHostStatus.createDate')" min-width="270">
            </el-table-column>
            <el-table-column prop="lastUpdate" :label="$t('taskHostStatus.lastUpdate')" min-width="270">
            </el-table-column>
        </el-table>
        <div class="mgtb20" :class="{ pagination : tableData.length !== 0}">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change ="handleCurrentChange"
                :page-sizes="$store.state.allTable.pageSizesChoice"
                :page-size="pageSizeGetter"
                layout="total, sizes, prev, pager, next, jumper"
                :total="sizeAll"
                :page-count="pageCount"
                v-if="tableData.length !== 0">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    import { mapGetters,mapMutations } from 'vuex';
    import common from '../../assets/script/common';
    export default {
        data() {
            return {
                tableData:[],
                pageName:'taskHostStatus',
                pageCount:1,
                sizeAll:0,
                dialogFormVisible: false,
                hasTaskClass: true,
                dialogType:'',
                searchId:'',
                tableDataLoading:true,
                searchForm:{
                    hostId:'',
                    hostIp:'',
                    status:'',
                    taskProject:'',
                    id:''
                },
            }
        },
        created() {
            this.getData(1,this.$store.state.allTable.pageSize);
        },
        computed:{
            ...mapGetters([
                "pageSizeGetter",
            ]),
        },
        methods:{
            ...mapMutations([
                'pageSizeMutation'
            ]),
            handleSizeChange(val) {
                let self = this;
                self.pageSizeMutation(val);
                self.getData(1,self.$store.state.allTable.pageSize);
            },
            handleCurrentChange(val) {
                common.changePageGoToTop(this,val);
            },
            getData(_pageSize, _pageNum) {
                let self = this;
                self.tableDataLoading = true;
                common.getTableList(this, 'taskHostStatu', _pageSize, _pageNum, self.searchForm, (data) => {
                    self.tableData = data.results ? data.results : [];
                    self.pageCount = data.pageCount;
                    self.sizeAll = data.sizeAll;
                    self.tableDataLoading = false;
                });
            },
            searchData() {
                let self = this;
                /*if(self.searchId !== ''){
                    common.searchTableList(self, 'taskHostStatus', self.searchId, (data) => {
                        self.tableData = [];
                        self.tableData.push(data);
                        self.pageCount = 1;
                        self.sizeAll = 1;
                    });
                }else{
                    self.getData(1,self.$store.state.allTable.pageSize);
                }*/
                self.getData(1,self.$store.state.allTable.pageSize);

            },
            refreshData() {
                let self = this;
                for(let key in self.searchForm){
                    self.searchForm[key] = '';
                }
                self.getData(1,self.$store.state.allTable.pageSize);
            },
            addButton() {
                let __ruleForm = this.ruleForm;
                for(let key in __ruleForm){
                    __ruleForm[key] = '';
                }
                this.dialogFormVisible = true;
                this.dialogType = 'add';
                this.hasTaskClass = true;
            }
        }
    }
</script>
<style lang="stylus">

</style>
